
#ifndef	__KC_SAKCAB_CUBIN_HPP_2010__
#define	__KC_SAKCAB_CUBIN_HPP_2010__

#include <vector>
#include <string>


#include <boost/thread/mutex.hpp>

#include "aubin.hpp"
#include "cuindex.hpp"
#include "oplog.hpp"

namespace   sakcab   {


class   Cubin	:	public Aubin
{

	typedef	CuIndex	index_type;
	typedef	CuIndex*	index_ptr;


public  :
    Cubin( const char* ini_filename, const char* ini_section );
    virtual	~Cubin();

public  :
    virtual	int insert( const std::string& kpin,
						const std::string& key,
						const std::string& data );

    virtual	int insertAppend( const std::string& kpin,
							  const std::string& key,
							  const std::string& data );

    virtual	int insertIgnore( const std::string& kpin,
							  const std::string& key,
							  const std::string& data );

    virtual	int find( const std::string& kpin,
					  const std::string& key,
							std::string& data );

    virtual	int find( const std::string& kpin,
					  const std::string&  key,
							std::vector< std::string >& data,
							u_int32_t     limit = 0 );

    virtual	int erase( const std::string& kpin,
					   const std::string& key );

	virtual	int	slim( void );

public  :

    virtual	int     insertAppend( const std::vector< std::string >& kpin,
								  const std::vector< std::string >& key,    
								  const std::vector< std::string >& data );

private :

	void	initialize(const char*, const char*);
	void	finalize( void );

	int		snapshot( void );

    const std::string   getSkeyByKpin( const std::string& kpin );

	index_ptr	getIndex( const std::string& kpin, const std::string key );

private :

	boost::mutex	_mutex;
	boost::mutex	_mutex_read;
    
private :
    AubinConfig _config;

	OpLog*   _oplog_p;

	index_ptr	_index_default_p;

	typedef	std::vector< index_ptr >	index_bins_type;
	index_bins_type	_index_bins;

	std::string	_idx_default_settings;

private	:
	// id of this object
	std::string	_id;
	AubinMeter	_meter;

	time_t		_when_last_snapshot;
};  //// class Cubin


}   //// namespace sakcab


#endif	////	__KC_SAKCAB_CUBIN_HPP_2010__

